home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5664 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: nntp.teleport.com!usenet
  2. From: GHouck <hksys@teleport.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: String Arrays and string parsing
  5. Date: 20 Feb 1996 10:29:32 GMT
  6. Organization: systems hk
  7. Message-ID: <4gc7qc$dm7@maureen.teleport.com>
  8. References: <31287278.789445@news.inforamp.net>
  9. NNTP-Posting-Host: ip-pdx04-22.teleport.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. dsheuman@inforamp.net (Danny Heuman) wrote:
  16. >I have day, month, and year as DDMMMYYYY and would like to parse it
  17. >out in to DD, MMM, YYYY.  I can parse the DD out by using
  18. >strncpy(into1, from1, 2).  I can parse the YYYY out by doing
  19. >strcpy(into3, from1 + 5).  How can I parse out the MMM?  Can I use
  20. >either of these functions that work above, strncpy or strcpy?  If so,
  21. >once parsed, do I have to attach an '\0' to the end of it to keep it
  22. >as a character string?
  23. >
  24. Danny,
  25. Yes, you can use 'strncpy'. Yes, you have to add zero. Try the following:
  26.  
  27.   strncpy( month,(datestring+2),3 ); /* copy MMM from interior */
  28.   month[3] = '\000';                 /* add null terminator */
  29.  
  30. Yours, Geoff Houck
  31.  
  32.  
  33.  
  34.